<?php
/**
 * 系統選項清單設定
 * @author cik
 *
 */
class Default_Model_Upgrade_SfsText extends Default_Model_Upgrade_Core
{
    protected $_table = 'sfs_text';
    protected $_targetTable = array('system_text');
    protected $_replace_arr = array(
'父母關係'=>'relation',
'家庭類型'=>'family_kind' ,
'家庭氣氛'=>'family_air',
'管教方式'=>'discipline_father' ,
'居住情形'=>'live_state' ,
'經濟狀況'=>'asset_state',
'喜愛困難科目'=>'scopes',
'特殊才能'=>'particular_ability',
    //'particular_martial_art' =>'特殊才能_武術',
    //'particular_musical_instruments' =>'特殊才能_樂器演奏',
'興趣'=>'interest',
'生活習慣'=>'living_habit',
'人際關係'=>'relationship',
'外向行為'=>'behavior_extrovert',
'內向行為'=>'behavior_introvert',
'學習行為'=>'behavior_learning',
'不良習慣'=>'bad_manner',
'焦慮行為'=>'behavior_anxiety',
 '日常行為表現'=>'normal_behavior_performance',
 '公共服務表現'=>'public_service_performancer',
 '校外特殊表現'=>'off_campus_particular_performance',
 '缺曠課類別'=>'absenteeism_category',
  '團體活動表現'=>'performance_in_group_activities',
    'addr' => 'address',
   '努力程度'=>'efforts_level',
    );

    function upgrade (){
        if ($this->isUpgrade())
        return 'isUpgrde';
        else {
            $query = "SELECT * FROM sfs_text";
            $res = $this->_sfs3Pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
            foreach($res as $row) {
                $arr = array();
                $arr['sn'] = $row['t_id'];
                $arr['sort']   = $row['t_order_id'];
                $arr['kind'] = $this->iconv($row['t_kind']);
                if ($row['g_id']==1)
                $arr['group_id'] = 'student';
                elseif($row['g_id']==2)
                $arr['group_id'] = 'teacher';
                elseif($row['g_id']==3)
                $arr['group_id'] = 'score';
                elseif($row['g_id']==4)
                $arr['group_id'] = 'system';
                elseif($row['g_id']==9)
                $arr['group_id'] = 'backup';

                $arr['id'] = $row['d_id'];
                $arr['name']   =$this->iconv($row['t_name']);
                $arr['t_parent']  =$row['t_parent'];
                $arr['parent_sn'] = $row['p_id'];
                $arr['parent_dot'] = $row['p_dot'];
/*
                $find = $this->newdb->fetchRow("SELECT id FROM system_text
				  WHERE	 sn = '{$arr['sn']}'
				  AND id ='{$arr['id']}'
				  AND group_id ='{$arr['group_id']}'
				  ");
                if ($find)
*/
                $this->fromArray('system_text',$arr);
            }
            foreach ($this->_replace_arr as $id=>$val){
                $query = "UPDATE system_text SET kind='$val' WHERE kind='$id'";
                $this->_newdbPdo->exec($query);
            }

            // 更改努力程度排序

          $query = "UPDATE system_text SET id=5 WHERE name='表現優異'";
          $this->_newdbPdo->exec($query);
          $query = "UPDATE system_text SET id=4 WHERE name='表現良好'";
          $this->_newdbPdo->exec($query);
          $query = "UPDATE system_text SET id=2 WHERE name='需再加油'";
          $this->_newdbPdo->exec($query);
          $query = "UPDATE system_text SET id=1 WHERE name='有待改進'";
          $this->_newdbPdo->exec($query);

          // 刪除不示目錄資料列
          $query = "DELETE FROM system_text WHERE kind='non_display'";
          $this->_newdbPdo->exec($query);

            $log['memo'] = 'sfs_text 升級';
            $log['upgrade_time']	= date("Y-m-d h:i:s");
            $this->finishUpgrade($log);
        }
    }
}